package com.yuw.oop.jbinnerclass;

public class Student {
    // 属性---成员变量【类范围中定义的变量】

    // 姓名属性
    private String stuName;
    // 年龄
    private int stuAge;
    // 学号
    private String stuNum;
    // 学校
    private String stuSchoolName;

    // 构造方法：默认的构造方法
    public Student() {
        System.out.println("调用了默认的构造方法");
    }

    // 构造方法：自定义的构造方法
    public Student(int stuAge, String stuNum, String stuSchoolName, String stuName) {
        this(); // 只能放在第一行
        System.out.println("调用了自定义的构造方法");
        this.stuAge = stuAge;
        this.stuNum = stuNum;
        this.stuSchoolName = stuSchoolName;
        this.stuName = stuName;
    }

    // getter/setter接口
    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public int getStuAge() {
        return stuAge;
    }

    public void setStuAge(int stuAge) {
        this.stuAge = stuAge;
    }

    public String getStuNum() {
        return stuNum;
    }

    public void setStuNum(String stuNum) {
        this.stuNum = stuNum;
    }

    public String getStuSchoolName() {
        return stuSchoolName;
    }

    public void setStuSchoolName(String stuSchoolName) {
        this.stuSchoolName = stuSchoolName;
    }

    // 行为---成员方法【类范围中定义的方法】

    /**
     * 学生学习的行为
     */
    public void doStuding() {
        System.out.println(stuName + " am do studing...");
        String strAddress = "tjise"; // 局部变量
        String stuName = "小明"; // 局部变量和成员变量名字一样，局部变量覆盖了成员变量的值
        // 判定原则：范围最小优先原则；就近原则；
        System.out.println(stuName + " am do studing at " + strAddress);
    }

    /**
     * 学生考试行为
     */
    public void exam() {
        System.out.println("I am examing...");
        // 局部变量
        String mySchool = "tjup";
        // 局部内部类
        class StuFamily {
            // 属性
            private String familyAddress;
            private String familyPhone;

            public StuFamily() {
            }

            public StuFamily(String familyAddress, String familyPhone) {
                this.familyAddress = familyAddress;
                this.familyPhone = familyPhone;
            }

            public String getFamilyAddress() {
                return familyAddress;
            }

            public void setFamilyAddress(String familyAddress) {
                this.familyAddress = familyAddress;
            }

            public String getFamilyPhone() {
                return familyPhone;
            }

            public void setFamilyPhone(String familyPhone) {
                this.familyPhone = familyPhone;
            }

            // 行为
            public void showFamilyInfo() {
                System.out.println("my name is " + stuName); //  可以访问外部类的成员变量
                System.out.println("外部类的局部变量：" + mySchool); // jvm8- 以前，要求被访问的局部变量必须是final类型；jvm8+以后，默认为final类型
                System.out.println("家庭信息：" + familyAddress);
            }

        }

        // 只能在这个范围使用局部内部类
        StuFamily stuFamily = new StuFamily("tjise", "10010");
        stuFamily.showFamilyInfo();

        //mySchool = "ttt";
    }

    /**
     * 学生玩游戏的行为
     */
    public void playGames() {
        System.out.println("I am playing games...");
    }


}
